import { Global, Module } from "@nestjs/common";
import { createTransport } from "nodemailer";
import configuration from "./configuration";

let emailTransporter = undefined;
if (configuration.email.enable) {
  emailTransporter = createTransport({
    host: configuration.email.host,
    port: configuration.email.port,
    secure: configuration.email.secure, // Use `true` for port 465, `false` for all other ports
    auth: {
      user: configuration.email.user,
      pass: configuration.email.pass,
    },
  });
}
const emailTransporterProvide = {
  provide: "Transporter",
  useValue: emailTransporter,
};

@Global()
@Module({
  providers: [emailTransporterProvide],
  exports: [emailTransporterProvide],
})
export class EmailModule {}
